package com.gragra.distances.tests;
import static org.junit.Assert.*;
import it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import org.junit.Test;
import com.gragra.distances.DistanceTools;
public class TestTools
{
	@Test
	public void testGetL2NormInt2ObjectMapOfInt2DoubleOpenHashMap()
	{
		Int2ObjectMap<Int2DoubleOpenHashMap> val = new Int2ObjectOpenHashMap<Int2DoubleOpenHashMap>();
		Int2DoubleOpenHashMap map = new Int2DoubleOpenHashMap();
		map.put(1, 2.0);
		map.put(5, 3.3);
		val.put(4, map);
		map = new Int2DoubleOpenHashMap();
		map.put(1, 4.5);
		map.put(5, 6.44);
		val.put(8, map);
		assertEquals(8.752919512939668,DistanceTools.getL2Norm(val),0.00000001);
	}
	@Test
	public void testGetL2NormDoubleArray()
	{
		double[] arr = new double[] {2.0,3.3,4.5,6.44};
		assertEquals(8.752919512939668,DistanceTools.getL2Norm(arr),0.00000001);
	}
	@Test
	public void testGetPNormDoubleArrayDouble()
	{
		double[] arr = new double[] {2.0,3.3,4.5,6.44};
		assertEquals(16.240000000000002,DistanceTools.getPNorm(arr,1.0),0.00000001);
	}
	@Test
	public void testGetPNormInt2ObjectMapOfInt2DoubleOpenHashMapDouble()
	{
		Int2ObjectMap<Int2DoubleOpenHashMap> val = new Int2ObjectOpenHashMap<Int2DoubleOpenHashMap>();
		Int2DoubleOpenHashMap map = new Int2DoubleOpenHashMap();
		map.put(1, 2.0);
		map.put(5, 3.3);
		val.put(4, map);
		map = new Int2DoubleOpenHashMap();
		map.put(1, 4.5);
		map.put(5, 6.44);
		val.put(8, map);
		assertEquals(16.240000000000002,DistanceTools.getPNorm(val,1.0),0.00000001);
	}
}